var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2GameConfiguration = require("GameConfiguration");
var $2NodeManager = require("NodeManager");
var $2ConstValue = require("ConstValue");
var $2GameUser = require("GameUser");
var $2levelbase = require("levelbase");
var $2UIManager = require("UIManager");
var $2UIHelp = require("UIHelp");
var $2UIPProp = require("UIPProp");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_level_ui = /* */function (_cc$Component38) {
  function _ctor() {
    var _this177;
    babel_classCallCheck(this, _ctor);
    _this177 = _callSuper(this, _ctor, arguments);
    _this177.level = null;
    _this177.bombBtn = null;
    _this177.addtimeBtn = null;
    _this177.bombUsedCount = 0;
    _this177.addtimeUsedCount = 0;
    return _this177;
  }
  babel_inherits(_ctor, _cc$Component38);
  return babel_createClass(_ctor, [{
    key: "onLoad",
    value: function onLoad() {
      for (var _e98 = 0; _e98 < this.node.children.length; _e98++) {
        var _t87 = this.node.children[_e98].name;
        if ("btn_bomb" == _t87) {
          this.bombBtn = this.node.children[_e98];
        } else {
          "btn_addTime" == _t87 && (this.addtimeBtn = this.node.children[_e98]);
        }
      }
    }
  }, {
    key: "getPropCount",
    value: function getPropCount(e) {
      if ("bomb" == e) {
        return $2GameUser.default.getInstance().bombCount;
      } else {
        if ("addtime" == e) {
          return 0;
        } else {
          return undefined;
        }
      }
    }
  }, {
    key: "changePropCount",
    value: function changePropCount(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
      "bomb" == e && ($2GameUser.default.getInstance().bombCount += t);
    }
  }, {
    key: "enter",
    value: function enter(e) {
      this.level = e.getComponent($2levelbase.default);
      this.bombBtn.active = $2GameConfiguration.default.getGFByType($2GameConfiguration.eGameFeatures.Bomb);
      this.addtimeBtn.active = $2GameConfiguration.default.getGFByType($2GameConfiguration.eGameFeatures.AddTime);
      this.bombUsedCount = 0;
      this.addtimeUsedCount = 0;
      this.refreshPropCount();
      $2ConstValue.ConstValue.IsGaming = true;
      $2NodeManager.default.Instance.closeTiliView();
    }
  }, {
    key: "exit",
    value: function exit() {
      this.level = null;
      this.bombBtn.active = false;
      this.addtimeBtn.active = false;
    }
  }, {
    key: "onBomb",
    value: function onBomb() {
      var _this178 = this;
      if (this.bombUsedCount >= 3) {
        $2UIHelp.UIHelp.showTip("本局炸弹次数已使用完");
      } else if (this.getPropCount("bomb")) {
        if ("function" == typeof this.level.useProp) {
          this.bombUsedCount++, this.level.useProp("bomb"), this.getPropCount("bomb") > 0 && (this.changePropCount("bomb", -1), this.refreshPropCount());
        }
      } else {
        $2UIManager.UIManager.getInstance().showUI($2UIPProp.default, function (e) {
          e.setData("bomb", _this178.bombUsedCount, function (e) {
            if (e) {
              _this178.bombUsedCount++;
              $2UIHelp.UIHelp.showMulTip([{
                text: "炸掉4个砖块成功"
              }, {
                icon: "icon_bomb",
                text: "炸弹x1"
              }]);
              _this178.level.useProp("bomb");
            }
          });
        });
      }
    }
  }, {
    key: "onAddTime",
    value: function onAddTime() {
      var _this179 = this;
      if (this.addtimeUsedCount >= 3) {
        $2UIHelp.UIHelp.showTip("使用次数已达到上限");
      } else if (this.getPropCount("addtime")) {
        if ("function" == typeof this.level.useProp) {
          this.addtimeUsedCount++, this.level.useProp("addtime"), this.getPropCount("addtime") > 0 && (this.changePropCount("addtime", -1), this.refreshPropCount());
        }
      } else {
        $2UIManager.UIManager.getInstance().showUI($2UIPProp.default, function (e) {
          e.setData("addtime", _this179.addtimeUsedCount, function (e) {
            if (e) {
              _this179.addtimeUsedCount++;
              $2UIHelp.UIHelp.showMulTip([{
                text: "时间已延长30s"
              }, {
                icon: "icon_addtime",
                text: "加时x1"
              }]);
              _this179.level.useProp("addtime");
            }
          });
        });
      }
    }
  }, {
    key: "refreshPropCount",
    value: function refreshPropCount() {
      if (2 == this.bombBtn.children.length) {
        var _e99 = this.getPropCount("bomb");
        this.bombBtn.children[1].active = false;
        this.bombBtn.children[0].active = _e99 > 0;
        this.bombBtn.children[0].getComponentInChildren(cc.Label).string = _e99.toString();
      }
      if (2 == this.addtimeBtn.children.length) {
        var _e100 = this.getPropCount("addtime");
        this.addtimeBtn.children[1].active = false;
        this.addtimeBtn.children[0].active = _e100 > 0;
        this.addtimeBtn.children[0].getComponentInChildren(cc.Label).string = _e100.toString();
      }
    }
  }, {
    key: "onEnable",
    value: function onEnable() {
      var e;
      var t;
      null === (e = this.bombBtn) || undefined === e || e.on("click", this.onBomb, this);
      null === (t = this.addtimeBtn) || undefined === t || t.on("click", this.onAddTime, this);
    }
  }, {
    key: "onDisable",
    value: function onDisable() {
      var e;
      var t;
      null === (e = this.bombBtn) || undefined === e || e.off("click", this.onBomb, this);
      null === (t = this.addtimeBtn) || undefined === t || t.off("click", this.onAddTime, this);
    }
  }]);
}(cc.Component);
def_level_ui = cc__decorate([ccp_ccclass], def_level_ui);
exports.default = def_level_ui;